package de.fhwf.mixedreality.client2008;

class CommandInterface {
 private String mCmd;
 private String mLastCmd;
 
 public CommandInterface() {
  mCmd = "";
  mLastCmd = "";
 }

 /** Command to set velocity */
 void setVelocity(int leftWheel, int rightWheel) {
  int left = vel2int(leftWheel);
  int right = vel2int(rightWheel);
  mCmd  = XMLProtocol.CommandWheelVelocities(left, right);
 }

 /** Setup a kick command */
 void setKick(double angle, double strength) {
	mCmd = XMLProtocol.CommandKick(angle, strength);
 }
 
 void setGoto(double dist, double angle) {
	 mCmd = XMLProtocol.CommandGoto(dist, angle);
 }

 /** Set a raw command */
 @Deprecated
 void setRaw(String cmd) { 
  mCmd = cmd;
 }
 
 void setMMPS(int left, int right) {
  mCmd  = XMLProtocol.CommandWheelVelocities(left, right);
 }
 
 /**
  * Returns the string with the command.
  * If no command was set string will be empty.
  * After this the command is eliminated
  * from memory.
  */
 String getCmd() {
  mLastCmd = mCmd;
  mCmd = "";
  return mLastCmd;
 }

 String getLastCmd() {
  return mLastCmd;
 }

 private int vel2int(int vel) {
  int mm = 0;
  switch (vel) {
   case -4:
    mm = -130;
    break;
   case -3:
  	mm = -130;
    break;
   case -2:
  	mm = -75; 
    break;
   case -1:
  	mm = -50; 
    break;
   case 1:
  	mm = 50; 
    break;
   case 2:
  	mm = 75; 
    break;
   case 3:
  	mm = 130; 
    break;
   case 4:
  	mm = 130;
  	break;
  }
  return mm;
 }
}